home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / Include / syncLock.h < prev    next >
C/C++ Source or Header  |  1991-08-09  |  5KB  |  173 lines

  1. /*
  2.  * syncLock.h --
  3.  *
  4.  *    Definitions of locks and semaphores. This has to be seperate from
  5.  *    sync.h to prevent circular dependencies with proc.h. See sync.h
  6.  *    for more information.
  7.  *    
  8.  *
  9.  * Copyright 1989 Regents of the University of California
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose and without
  12.  * fee is hereby granted, provided that the above copyright
  13.  * notice appear in all copies.  The University of California
  14.  * makes no representations about the suitability of this
  15.  * software for any purpose.  It is provided "as is" without
  16.  * express or implied warranty.
  17.  *
  18.  * $Header: /sprite/src/kernel/sync/RCS/syncLock.h,v 1.7 91/05/06 14:51:33 kupfer Exp $ SPRITE (Berkeley)
  19.  */
  20.  
  21. #ifndef _SYNCLOCK
  22. #define _SYNCLOCK
  23.  
  24. /* 
  25.  * Don't include procTypes.h.  The actual definition of "struct 
  26.  * Proc_ControlBlock" isn't needed for holderPCBPtr, and including it 
  27.  * introduces a dependency loop (because it needs the definition of 
  28.  * Sync_Semaphore, which is defined below). 
  29.  */
  30.  
  31. #ifdef KERNEL
  32. #include <user/list.h>
  33. #include <user/sync.h>
  34. #else
  35. #include <list.h>
  36. #include <sync.h>
  37. #endif
  38.  
  39. /*
  40.  * If CLEAN_LOCK is defined then don't register locks and don't keep track
  41.  * of lock dependency pairs.
  42.  */
  43. #ifdef CLEAN_LOCK
  44. #undef LOCKREG
  45. #undef LOCKDEP
  46. #endif
  47.  
  48. /*
  49.  * If LOCKDEP is  defined then we need to register locks.
  50.  */
  51. #ifdef LOCKDEP
  52. #define LOCKREG
  53. #endif
  54.  
  55. /*
  56.  *  Maximum types of locks. Types are assigned as locks are registered, 
  57.  *  starting at 1. No distiction is made between locks and semaphores when
  58.  *  assigning a type. The type is used as an index into the array of
  59.  *  statistics for that lock type. Unregistered locks have a type of 0,
  60.  *  and the type of the lock that protects the lock registration itself is
  61.  *  -1. We have to treat this lock specially because a lock is registered
  62.  *  after it is locked, and we need to lock the registration lock in order
  63.  *  to register a lock. Hence we can't register the registration lock.
  64.  */
  65.  
  66. #define SYNC_MAX_LOCK_TYPES 60
  67.  
  68. /*
  69.  * This is used inside the Sync_Semaphore and Sync_Lock structures to allow
  70.  * them to be linked into lists. Usually the links field is first in a
  71.  * structure so that the list routines work correctly. The CLEAN_LOCK
  72.  * version of locks do not use the links field and expect the value of
  73.  * the lock to be the first field. The easiest solution is to put the
  74.  * links inside a structure which in turn is inside the locks. The linked
  75.  * list elements are these inner structures, which in turn have a pointer
  76.  * to the lock that contains them.
  77.  */
  78. typedef struct Sync_ListInfo {
  79.     List_Links    links;        /* used to link into lists */
  80.     Address    lock;        /* ptr at outer structure that contains this
  81.                  * structure */
  82. } Sync_ListInfo;
  83.  
  84. #define SYNC_LISTINFO_INIT  \
  85.     {{(struct List_Links *) NIL,(struct List_Links *) NIL}, (Address) NIL}
  86. /*
  87.  * Classes of locks. The "class" field of both locks and semaphores is 
  88.  * at the same offset within the structures. This allows routines to determine
  89.  * the class of a parameter.
  90.  */
  91. typedef enum Sync_LockClass {
  92.     SYNC_SEMAPHORE,            
  93.     SYNC_LOCK
  94. } Sync_LockClass;
  95.  
  96. /*
  97.  * Structure that defines a semaphore or spin lock.
  98.  */
  99. typedef struct Sync_Semaphore {
  100.     /*
  101.      * The value field must be first.
  102.      */
  103.     int value;                /* value of semaphore */
  104.  
  105. #ifdef LOCKREG
  106.     int miss;                /* count of misses on lock */
  107.     int    hit;                /* count of lock hits */
  108.     /*
  109.      * The class field must be at the same offset in both locks and semaphores.
  110.      */
  111.     Sync_LockClass class;        /* class of lock (semaphore) */
  112.     int type;                /* id of lock name */
  113.     Sync_ListInfo listInfo;        /* used to link these into lists */
  114. #endif /* LOCKREG */
  115.  
  116. #ifndef CLEAN_LOCK
  117.     char *name;                /* name of semaphore */
  118.     Address holderPC;            /* pc of lock holder */
  119.     struct Proc_ControlBlock *holderPCBPtr; /* process holding lock */
  120. #endif /*CLEAN_LOCK */
  121.  
  122. #ifdef LOCKDEP
  123.     int priorCount;            /* count of locks that were grabbed
  124.                      * immediately before this one */
  125.     int priorTypes[SYNC_MAX_PRIOR];     /* types of prior locks */
  126. #endif /* LOCKDEP */
  127.  
  128. } Sync_Semaphore;
  129.  
  130. /*
  131.  * Structure that defines a kernel monitor lock.
  132.  */
  133.  
  134. typedef struct Sync_KernelLock{
  135.     /*
  136.      * The inUse and waiting fields must be first and in this order.
  137.      */
  138.     Boolean inUse;            /* 1 while the lock is busy */
  139.     Boolean waiting;                /* 1 if someone wants the lock */
  140. #ifdef LOCKREG
  141.     int hit;                /* number of times lock is grabbed */
  142.     /*
  143.      * The class field must be at the same offset in both locks and semaphores.
  144.      */
  145.     Sync_LockClass class;        /* class of lock (lock) */
  146.     int type;                /* type of lock */
  147.     Sync_ListInfo listInfo;        /* used to put locks into lists */
  148.     int miss;                /* number of times lock is missed */
  149. #endif /* LOCKREG */
  150.  
  151. #ifndef CLEAN_LOCK
  152.     char *name;                /* name of lock type */
  153.     Address holderPC;            /* pc of lock holder */
  154.     struct Proc_ControlBlock *holderPCBPtr; /* process holding lock */
  155. #endif /*CLEAN_LOCK */
  156.  
  157. #ifdef LOCKDEP
  158.     int priorCount;            /* count of locks that were grabbed
  159.                      * immediately before this one */
  160.     int priorTypes[SYNC_MAX_PRIOR];     /* types of prior locks */
  161.  
  162. #endif /* LOCKDEP */
  163. } Sync_KernelLock;
  164.  
  165.  
  166. #ifdef KERNEL
  167. typedef Sync_KernelLock Sync_Lock;    /* define locks for kernel */
  168. #endif
  169.  
  170.  
  171. #endif /* _SYNCLOCK */
  172.  
  173.